package com.cskaoyan.service;

import com.cskaoyan.mapper.MarketAddressMapper;
import com.cskaoyan.model.MarketAddress;
import com.cskaoyan.model.MarketAddressExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description
 * @Author zoe ling
 * @Date 2024/6/13
 */
@Service
public class AddressServiceImpl implements AddressService {
    @Autowired
    MarketAddressMapper addressMapper;

    @Override
    public MarketAddress queryDefault(Integer userId) {
        MarketAddressExample example = new MarketAddressExample();
        example.createCriteria()
                .andUserIdEqualTo(userId)
                .andIsDefaultEqualTo(true)
                .andDeletedEqualTo(false);
        List<MarketAddress> marketAddresses = addressMapper.selectByExample(example);
        return marketAddresses!=null&&marketAddresses.size()==1?marketAddresses.get(0):null;
    }

    @Override
    public MarketAddress findById(Integer addressId) {
        MarketAddressExample example = new MarketAddressExample();
        example.createCriteria()
                .andIdEqualTo(addressId)
                .andDeletedEqualTo(false);
        List<MarketAddress> marketAddresses = addressMapper.selectByExample(example);
        return marketAddresses!=null&&marketAddresses.size()==1?marketAddresses.get(0):null;
    }
}
